<?
    final class Principio_Model_OptionMapper extends Principio_Mapper
    {
        /*
         * Options
         */
        protected static $db_table = null;
        protected static function getDbTableName() { return "Option"; }



        // Firmware
        const OPTION_UPGRADE_ERROR_RETRY_DELAY = "upgrade_error_retry_delay";

        // DNS
        const OPTION_DNS_PRIMARY = "dns_primary";
        const OPTION_DNS_SECONDARY = "dns_secondary";
        const OPTION_DNS_SERVER_ORDER = "dns_server_order";
        const OPTION_DNS_QUERY_MODE = "dns_query_mode";

        // Common
        const OPTION_RESYNC_PERIODIC = "resync_periodic";

        // Web server
        const OPTION_WEB_SERVER_ENABLE = "web_server_enable";
        const OPTION_WEB_SERVER_PORT = "web_server_port";
        const OPTION_WEB_ADMIN_ACCESS_ENABLE = "web_admin_access_enable";
        const OPTION_WEB_ADMIN_PASSWORD = "web_admin_password";


        public static function fetch($option)
        {
            try
            {

                $select = self::getDBTable()->select()->where("caption=?", $option);
                $values = self::getDBTable()->fetchRow($select);

                return new Principio_Model_Option($values->toArray());
            }
            catch (Exception $ex)
            {
                return self::reportException($ex);
            };
        }


        public static function fetchAll()
        {
            try
            {
                $values = self::getDBTable()->fetchAll();
                return Principio_Model_Option::makeCollection($values->toArray());
            }
            catch (Exception $ex)
            {
                return self::reportException($ex);
            };
        }


        public static function save(Principio_Model_Option $model_option)
        {
            try
            {
                $data = ['value' => $model_option->getValue()];
                return self::getDBTable()->update($data, ['id=?' => $model_option->getID()]);
            }
            catch (Exception $ex)
            {
                return self::reportException($ex);
            };
        }
    }
?>